package com.example.demo.service.impl;

import com.example.demo.entity.Comment;
import com.example.demo.mapper.CommentsMapper;
import com.example.demo.service.CommentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {

    @Resource
    CommentsMapper commentsMapper;


    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public List<Comment> getAllComments() {
        return commentsMapper.getAllComments();
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public List<Comment> getCommentsByOrderId(Long orderId) {
        return commentsMapper.getCommentsByOrderId(orderId);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public List<Comment> getCommentsByUserId(Long userId) {
        return commentsMapper.getCommentsByUserId(userId);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public Comment getCommentsByUserIdAndOrderId(Long userId, Long orderId) {
        return commentsMapper.getCommentsByUserIdAndOrderId(userId,orderId);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void deleteCommentByCommentId(Long commentId) {
        commentsMapper.deleteCommentByCommentId(commentId);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void deleteCommentByUserIdAndOrderId(Long userId, Long orderId) {
        commentsMapper.deleteCommentByUserIdAndOrderId(userId,orderId);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void newComment(Comment comment) {
        commentsMapper.newComment(comment);
    }
}

